<?php
/**
 * Setting parameters of templates in an article without leaving the article page.
 *
 * @author Stephan Gambke
 * @version 0.1 alpha
 */


if ( !defined( 'MEDIAWIKI' ) ) {
	die( 'This file is a MediaWiki extension, it is not a valid entry point.' );
}

if ( !defined( 'SF_VERSION' ) ) {
	die( 'This is a Semantic Forms extension. You need to install Semantic Forms first.' );
}

define( 'FE_VERSION', '0.1 alpha' );

// register extension
$wgExtensionCredits[defined( 'SEMANTIC_EXTENSION_TYPE' ) ? 'semantic' : 'other'][] = array(
	'path' => __FILE__,
	'name' => 'FloatEdit',
	'author' => array( '[http://www.mediawiki.org/wiki/User:F.trott Stephan Gambke]' ),
	'url' => 'http://www.mediawiki.org/wiki/Extension:FloatEdit',
	'descriptionmsg' => 'floatedit-desc',
	'version' => FE_VERSION,
);


// extension settings
$fefScriptPath = $wgScriptPath . "/extensions/FloatEdit";


// register extensions resources
$dir = dirname( __FILE__ );

$wgExtensionMessagesFiles['FloatEdit'] = $dir . '/FloatEdit.i18n.php';
$wgAutoloadClasses['FloatEdit'] = $dir . '/FloatEdit.body.php';

// register with ResourceLoader if defined
if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {

	$wgResourceModules['ext.FloatEdit'] = array(
		// JavaScript and CSS styles.
		'scripts' => 'libs/floatedit.js',
		'styles' => 'skins/floatedit.css',
		// When the module is loaded, these messages will be available to mediaWiki.msg()
		//'messages' => array( 'floatedit-desc' ),
		// Dependencies
		// listing jquery is not strictly necessary, but it does not hurt either
		'dependencies' => array( 'jquery' ),
		// subdir relative to "extensions" or $wgExtensionAssetsPath
		'localBasePath' => $dir,
		'remoteExtPath' => 'FloatEdit'
	);
};


# Define a setup function
$wgHooks['ParserFirstCallInit'][] = 'fefParserFunction_Setup';

# Add a hook to initialise the magic word
$wgHooks['LanguageGetMagic'][] = 'fefParserFunction_Magic';


function fefParserFunction_Setup ( &$parser ) {
	global $wgOut;

	// TODO: obsolete as of MW 1.16, remove around 1.18 or so
	wfLoadExtensionMessages( 'FloatEdit' );

	// Set a function hook associating the "floatedit" magic word with our function
	$parser->setFunctionHook( 'floatlink', 'FloatEdit::renderFloatLink' );
	$parser->setFunctionHook( 'floatinput', 'FloatEdit::renderFloatInput' );

	// load jQuery
	$wgOut->includeJQuery();  // only necessary in MW 1.16, does nothing in MW 1.17+

	return true;
}

function fefParserFunction_Magic ( &$magicWords, $langCode ) {
	// Add the magic word
	// The first array element is whether to be case sensitive
	// 0 is not case sensitive, 1 is be sensitive
	// All remaining elements are synonyms for the parser function
	$magicWords['floatlink'] = array( 1, 'floatlink' );
	$magicWords['floatinput'] = array( 1, 'floatinput' );

	// unless we return true, other parser functions extensions won't get loaded.
	return true;
}
